const webpack = require("webpack");
const autoprefixer = require("autoprefixer");
const path = require("path");

// 屏幕适配
const px2rem = require("postcss-px2rem")
// 配置基本大小
const postcss = px2rem({
  //配rem基准值 基准大小 baseSize
  remUnit: 10,// 设稿尺1920/10
})


function resolve(dir) {
  return path.join(__dirname, dir);
}


module.exports = {
  // 路径配置别名
  chainWebpack: config => {
    config.resolve.alias
      .set("@", resolve("./src"))
      .set("@assets", resolve("./src/assets"))
      .set("@request", resolve("./src/request"))
      .set("@views", resolve("./src/views"))
      .set("@components", resolve("./src/components"));
  },
  publicPath: "/screen",
  productionSourceMap: false,
  filenameHashing: false,
  lintOnSave: false,

  //jq配置
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery"
      })
    ],
    //高德地图
    externals: {
      AMap: "AMap"
    }
  },
  devServer: {
    open: true,
    host: "0.0.0.0",
    port: 8084,
    https: false,
    hotOnly: false,
    proxy: {
      "/api": {
        // target: 'http://192.168.3.43:90',
        target: 'https://zhzf.aizhangzi.com/api',
        // target:"http://10.7.0.14:90",
        // target:"http://223.15.229.108:90/api",
        changeOrigin: true,
        pathRewrite: {
          "^/api": ""
        }
      },
      "/other": {
        // target: 'https://dbapi.fancysx.com/api',
        target: 'http://221.204.12.174:9065/api',
        changeOrigin: true,
        pathRewrite: {
          "^/other": ""
        }
      },
      "/ljxq": {
        // target: 'http://192.168.3.58:82',
        target: 'http://221.204.12.174:9064/api',
        changeOrigin: true,
        pathRewrite: {
          "^/ljxq": ""
        }
      },
      "/ypsd": {
        // target: 'http://192.168.3.58:82',
        target: 'http://221.204.12.174:9064/api',
        changeOrigin: true,
        pathRewrite: {
          "^/ypsd": ""
        }
      },
    }
  },
  //  rem单位适配
  css: {
    sourceMap: false,
    loaderOptions: {
      postcss: {
        plugins: [
          postcss,
          autoprefixer() //加前缀
        ]
      }
    }
  },

  // less
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "less"
    }
  }
};